package lixp.shiro.config;

import lixp.res.Result;
import lixp.res.ResultEnum;
import lixp.res.ResultUtil;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * https://blog.csdn.net/bicheng4769/article/details/86680955
 * 这里是为什么要写这个异常处理的原因
 */
@ControllerAdvice
public class NoPermissionException {
    @ResponseBody
    @ExceptionHandler( UnauthorizedException.class)
    public Result handleShiroException(Exception ex) {
        return ResultUtil.error(ResultEnum.NOT_ROLE);
    }
    @ResponseBody
    @ExceptionHandler( AuthorizationException.class)
    public Result AuthorizationException(Exception ex) {
        return ResultUtil.error(ResultEnum.NOT_ROLE);
    }
}
